/**
 * @author Anix
 */

import com.xvm.Logger;
import com.xvm.Utils;

/**
 * EquipmentLoader
 * Custom context menu in Tank Carousel
 */

class wot.hangar.controls.CarouselItemRenderer extends net.wargaming.controls.CarouselItemRenderer

{
	    function CarouselItemRenderer()
    {
        Utils.TraceXvmModule("hangar_CarouselItemrenderer");
				//Logger.addObject(_root.contentHolder.main, "_root.contentHolder.main", 3);
				//Logger.addObject(_root.contentHolder.main.carousel, "_root.contentHolder.main.carousel", 3);
				Logger.add("_root.contentHolder.main.carousel._selectedIndex=" + _root.contentHolder.main.carousel._selectedIndex);
				//Logger.addObject(_root.contentHolder.main.fitting.elements, "_root.contentHolder.main.fitting.elements", 3);
				
				//Logger.addObject(_root.contentHolder.main.fitting.devices.optionalDevice1.dataValues, "_root.contentHolder.main.fitting.devices1", 3);
				//Logger.add("OptD_1=" + _root.contentHolder.main.fitting.devices.optionalDevice1.selectedIndex);
				
				//Logger.addObject(_root.contentHolder.main.fitting.devices.optionalDevice2.dataValues, "_root.contentHolder.main.fitting.devices2", 3);
				//Logger.add("OptD_2=" + _root.contentHolder.main.fitting.devices.optionalDevice2.selectedIndex);
				
				//Logger.addObject(_root.contentHolder.main.fitting.devices.optionalDevice3.dataValues, "_root.contentHolder.main.fitting.devices3", 3);
				//Logger.add("OptD_3=" + _root.contentHolder.main.fitting.devices.optionalDevice3.selectedIndex);
				
				//Logger.addObject(_root.contentHolder.main.fitting.equipments.elements, "_root.contentHolder.main.fitting.equipments.elements", 3);
				//Logger.addObject(_root.contentHolder.main, "_root.contentHolder.main", 2);
				//Logger.addObject(_root.contentHolder.main.fitting.equipments.elements.equipment1, "contentHolder.main.fitting.equipments.elements.equipment1", 3);	
				//Logger.addObject(_root.contentHolder.main.fitting.equipments.elements.equipment2, "contentHolder.main.fitting.equipments.elements.equipment2", 3);
				//Logger.addObject(_root.contentHolder.main.fitting.equipments.elements.equipment3, "contentHolder.main.fitting.equipments.elements.equipment3", 3);
				
		
		super();
        Mouse.addListener(this);
    } // End of the function
	
    function get doubleXpVal()
    {
        return (_doubleXpVal);
    } // End of the function
    function set doubleXpVal(value)
    {
        _doubleXpVal = Number(value) <= 1 || isNaN(Number(value)) ? (0) : (value);
        _doubleXpValDirty = true;
        this.invalidate();
        //return (this.doubleXpVal());
        //null;
    } // End of the function
	
    function setData(data)
    {
        if (data)
        {
            _visible = true;
            this.data = data;
            this.__set__id(data.id);
            this.__set__label(data.label);
            this.__set__image(data.image);
            this.__set__nation(data.nation);
            this.__set__level(data.level);
            this.__set__stat(data.stat);
            this.__set__tooltip(data.tooltip);
            this.__set__current(data.current);
            this.__set__empty(data.empty);
            this.__set__buyTank(data.buyTank);
            this.__set__buySlot(data.buySlot);
            this.__set__favorite(data.favorite);
            if (typeof(data.doubleXPReceived) == "boolean" && data.doubleXPReceived)
            {
                data.doubleXPReceived = 2;
            } // end if
            this.__set__doubleXpVal(data.doubleXPReceived);
            _dataDirty = true;
            this.invalidate();
        } // end if
    } // End of the function
    
	function configUI()
    {
        super.configUI();
        if (slot_price instanceof net.wargaming.controls.IconText)
        {
            slot_price.__set__text(data.slotPrice);
        } // end if
        var _loc4 = new Date();
        var _loc3 = Math.round(data.clanLock - _loc4.valueOf() / 1000);
        if (_loc3 > 0 && !data.buyTank && !data.buySlot && !data.empty)
        {
            clanLock_mc.timer.text = this.calcLockTime(_loc3);
            clanLock_mc._visible = true;
            stat_txt._y = Math.round(clanLock_mc._y - stat_txt.textHeight);
        }
        else
        {
            clanLock_mc._visible = false;
        } // end else if
        if (data.emptyLen > 1 && this.__get__stat() == "buyTank")
        {
            empty_info_txt.text = "#menu:tankCarousel/vehicleStates/buyTankEmptyCount";
            empty_info_txt.text = empty_info_txt.text + " " + data.emptyLen;
            empty_info_txt._visible = true;
        }
        else
        {
            empty_info_txt.text = "";
            empty_info_txt._visible = false;
        } // end else if
    } // End of the function
	
    function draw()
    {
        super.draw();
        if (_doubleXpValDirty && vehicleIcon)
        {
            vehicleIcon.__set__multyXpVal(doubleXpVal);
            _doubleXpValDirty = false;
        } // end if
        if (_dataDirty && vehicleIcon)
        {
            slot_price.__set__text(data.slotPrice);
            vehicleIcon.__set__showMultyXp(!(data.buyTank || data.buySlot || data.empty));
            vehicleIcon.__set__isPremium(data.premium);
            vehicleIcon.__set__isElite(data.elite);
            vehicleIcon.__set__tankType(data.tankType);
            _dataDirty = false;
        } // end if
        if (_doubleXpValDirty || _dataDirty)
        {
            this.invalidate();
        } // end if
    } // End of the function
	
    function calcLockTime(unixtime)
    {
        var _loc3 = "";
        unixtime = Math.ceil(unixtime / 60);
        var _loc1 = Math.floor(unixtime / 60);
        var _loc2 = Math.floor(unixtime - _loc1 * 60);
        var _loc6 = _loc1 < 10 ? ("0" + _loc1) : (_loc1);
        var _loc5 = _loc2 < 10 ? ("0" + _loc2) : (_loc2);
        _loc3 = _loc6 + ":" + _loc5;
        return (_loc3);
    } // End of the function
	
    function onMouseDown(button, target)
    {
        net.wargaming.managers.ToolTipManager.__get__instance().hide();
        if (Mouse.RIGHT == button)
        {
            for (var _loc2 = Mouse.getTopMostEntity(); _loc2; _loc2 = _loc2._parent)
            {
                if (_loc2 == this && !data.empty && !data.buySlot && !data.buyTank && !_parent._parent.isScrolling)
                {
                    menu = net.wargaming.managers.ContextMenuManager.__get__instance().show([["test"],["vehicleInfo"], [{id: "vehicleSell", disabled: !data.canSell}], ["vehicleResearch"], [!data.favorite ? ("vehicleCheck") : ("vehicleUncheck")]]);
					//menu = net.wargaming.managers.ContextMenuManager.__get__instance().show([["vehicleInfo"], [{id: "vehicleSell", disabled: !data.canSell}], ["vehicleResearch"], [!data.favorite ? ("vehicleCheck") : ("vehicleUncheck")]]);
                    menu.addEventListener("action", this, "actionsMenuItemClick");
                } // end if
            } // end of for
        } // end if
		

		
    } // End of the function
    function actionsMenuItemClick(args)
    {
        switch (args.id)
        {
            case "test":
			{
			//************ Полезные переменные
				//Logger.add("Hangar_vehicleInfo data.compactDescr=" + data.compactDescr);
				//Logger.add("Hangar_vehicleInfo data.label=" + data.label);
				//Logger.addObject(data.id, "Hangar_vehicleInfo data.id");
				//Logger.addObject(_root.contentHolder.main.fitting.elements, "_root.contentHolder.main.fitting.elements", 3);
				//Logger.addObject(_root.contentHolder.main.fitting.devices.optionalDevice1.dataValues.name, "_root.contentHolder.main.fitting.devices1", 3);
				//Logger.add("OptD_1=" + _root.contentHolder.main.fitting.devices.optionalDevice1.selectedIndex);
				
				//Logger.addObject(_root.contentHolder.main.fitting.devices.optionalDevice2.dataValues.name, "_root.contentHolder.main.fitting.devices2", 3);
				//Logger.add("OptD_2=" + _root.contentHolder.main.fitting.devices.optionalDevice2.selectedIndex);
				
				//Logger.addObject(_root.contentHolder.main.fitting.devices.optionalDevice3.dataValues.name, "_root.contentHolder.main.fitting.devices3", 3);
				//Logger.add("OptD_3=" + _root.contentHolder.main.fitting.devices.optionalDevice3.selectedIndex);
				
				//Logger.addObject(_root.contentHolder.main.tankmen, "_root.contentHolder.main.tankmen", 3);
				//------------------------
				//Logger.addObject(_root.contentHolder.main.carousel.renderers, "_root.contentHolder.main.carousel.renderers", 3);
				
				break;	
			}
			case "vehicleInfo":
            {
				_root.showTankInfoWnd(this.__get__id(), true);
                break;
            } 
            case "vehicleSell":
            {
                net.wargaming.managers.LobbyPopUpsDispatcher.__get__instance().showVehicleSellDialog(data.inventoryId);
                break;
            } 
            case "vehicleResearch":
            {
                if (_root.loadResearchItems != null)
                {
                    _root.loadResearchItems(data.compactDescr, "hangar");
                } // end if
                break;
            } 
            case "vehicleCheck":
            {
                gfx.io.GameDelegate.call("hangar.favoriteVehicle", [data.id, true]);
                break;
            } 
            case "vehicleUncheck":
            {
                gfx.io.GameDelegate.call("hangar.favoriteVehicle", [data.id, false]);
                break;
            } 
        } // End of switch
    } // End of the function
	
    function sellVehicle()
    {
        gfx.io.GameDelegate.removeCallBack("hangar.sellVehicle", this, "sellVehicle");
        var _loc4 = Boolean(arguments.shift());
        var args = arguments;
        if (_loc4)
        {
            var _loc3 = net.wargaming.notification.MessageDialog.show("vehicleSell/unique", true, true);
            _loc3.addEventListener("submit", this, "onSellVehicleShow");
            _loc3.getSubmitData = function ()
            {
                return (args);
            };
        }
        else
        {
            this.onSellVehicleShow({data: arguments});
        } // end else if
    } // End of the function
    function onSellVehicleShow(args)
    {
        var _loc2 = net.wargaming.dialogs.VehicleSellDialog.show("vehicleSellDialog", args.data);
        _loc2.addEventListener("submit", this, "onSellVehicleConfirm");
    } // End of the function
    function onSellVehicleConfirm(event)
    {
        net.wargaming.managers.PersonalCaseManager.__get__instance().closeAllManagedWindow();
        gfx.io.GameDelegate.call("hangar.sellVehicle", [event.data.id, event.data.isUnload, event.data.isDismantling]);
    } // End of the function
}